package com.nowcoder.community.config;

import com.nowcoder.community.controller.interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName WebMvcConfig
 * @Description
 * @Author hhwu
 * @Date 2022/5/20 11:29
 * Version 1.0
 **/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private TestInterceptor testInterceptor;// 测试案例，无具体含义

    @Autowired
    private LoginTicketInterceptor loginTicketInterceptor;// 拦截

//    用security代替处理
//    @Autowired
//    private LoginRequiredInterceptor loginRequiredInterceptor;// 拦截未登录情况下访问需要登录才能访问的资源

    @Autowired
    private MessageInterceptor messageInterceptor;// 计算所有未读消息数量  私信+系统通知

    @Autowired
    private DataInterceptor dataInterceptor;// 统计UV

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * @Author hhwu
         * @Description //TODO 添加拦截器（已经在interceptor包中配置好了）
         * @Date 11:34 2022/5/20
         * @Param [registry]
         * @return void
         **/
        registry.addInterceptor(testInterceptor)// 学习知识点时的测试
                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg")// 明确要排查的静态资源路径
                .addPathPatterns("/register", "/login");// 明确要拦截的请求

        registry.addInterceptor(loginTicketInterceptor);// 对携带登录凭证的请求传入对应的user对象

//        registry.addInterceptor(loginRequiredInterceptor)// 拦截未登录情况下访问需要登录才能访问的资源
//                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg");// 明确要排查的静态资源路径

        registry.addInterceptor(messageInterceptor)// 计算所有未读消息数量
                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg");// 明确要排查的静态资源路径

        registry.addInterceptor(dataInterceptor)// 统计UV，只拦动态资源的访问
                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg");// 明确要排查的静态资源路径
    }
}
